home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 440_01 / examples / ex_1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-16  |  3.8 KB  |  70 lines

  1. #include <stdio.h>
  2. #include "colors.h"
  3. #include "!bestlib.h"
  4.  
  5.    /*** NOTE  the names and structure of the routines used in these examples
  6.               have changed in The Best Library 2.00; the updated examples will
  7.               be released soon                                            ***/
  8.  
  9.    /*** NOTE  even though this program only uses the "keyp" structure, the
  10.               other three are necessary for the assembler routines in the
  11.               !BESTLIB.LIB library to function properly.  C would also
  12.               produce a "linker warning" if you have enabled that warning ***/
  13. filldata fidata;                       /* create a "filldata" structure     */
  14. printdata prdata;                      /* create a "printdata" structure    */
  15. mousedata msdata;                      /* create a "mousedata" structure    */
  16. asciiscan keyp;                        /* create an "asciiscan" structure   */
  17.  
  18. void main(void)
  19. {
  20.    int oldmode;
  21.    char *errmsg;
  22.  
  23.    oldmode = readvideomode();          /* save the current video mode       */
  24.    textm(0);                           /* make sure we are in text mode     */
  25.    textmem(3);                         /* store text video memory           */
  26.    cursor(3, 1);                       /* hide and store cursor position    */
  27.    clear(LIGHTGRAY, BLACK);            /* clear the screen and set colors   */
  28.  
  29.    do {
  30.       printsatxy("Select an option:", 5, 3);
  31.       printsatxy("1) Load", 8, 5);
  32.       printsatxy("2) Save", 8, 6);
  33.       printsatxy("3) Shell to DOS", 8, 7);
  34.       printsatxy("4) Exit program", 8, 8);       /* print small sample menu */
  35.  
  36.       getchr();                        /* wait for a user response          */
  37.       switch(keyp.ascii) {
  38.       case '1':                        /* load was selected                 */
  39.          beep();                       /* beep the speaker                  */
  40.          printsatxy("The Load option has not yet been written", 5, 24);
  41.          break;                        /* exit from switch statement        */
  42.       case '2':
  43.          beep();                       /* beep the speaker                  */
  44.          printsatxy("The Save option has not yet been written", 5, 24);
  45.          break;                        /* exit from switch statement        */
  46.       case '3':                        /* shell to DOS was selected         */
  47.          cursor(1, 1);                 /* show and restore cursor position  */
  48.          if ((errmsg = dosshell()) != NULL)
  49.             printsatxy(errmsg, 5, 24); /* print the returned error message  */
  50.          else {                        /* else if no error occurred..       */
  51.             cursor(3, 0);              /* hide and store ignore position    */
  52.             clear(LIGHTGRAY, BLACK);   /* clear the screen and set colors   */
  53.             printsatxy("Welcome back!", 5, 24);
  54.          }
  55.          break;                        /* exit from switch statement        */
  56.       case '4':                        /* exit program was selected         */
  57.          changevideomode(oldmode);     /* restore the original video mode   */
  58.          if (oldmode == 3 || oldmode == 7 || oldmode == 21) {
  59.                                        /* if the old mode was a text mode.. */
  60.             textmem(1);                /* restore text video memory         */
  61.             cursor(1, 1);              /* show and restore cursor position  */
  62.          }
  63.          break;                        /* exit from switch statement        */
  64.       default:                         /* the user pressed an invalid key   */
  65.          printsatxy("That is not a valid choice              ", 5, 24);
  66.          beep();                       /* beep the speaker to denote error  */
  67.       }
  68.    } while (keyp.ascii != '4');        /* loop until exit is chosen         */
  69. }
  70.